﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace LED_Editor
{
    public class GradientPanel:Panel
    {
        public Color StartColor { get; set; }
        public Color EndColor { get; set; }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            //e.ClipRectangle. 
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

            //Brush brush = new LinearGradientBrush(e.ClipRectangle, StartColor, EndColor, LinearGradientMode.Horizontal);     
            //e.Graphics.FillRectangle(brush,e.ClipRectangle);

            Brush brushStart = new SolidBrush(StartColor);
            Brush brushEnd = new SolidBrush(EndColor);

            Rectangle rect = ClientRectangle;
            Point topLeft = rect.Location;
            Point bottomLeft = new Point(rect.Location.X, rect.Location.Y + rect.Height);

            Point topRight = new Point(rect.Location.X + rect.Width, rect.Location.Y);
            Point bottomRight = new Point(rect.Location.X + rect.Width, rect.Location.Y + rect.Height);


            e.Graphics.FillPolygon(brushStart, new Point[] { topLeft, topRight, bottomLeft, topLeft });
            e.Graphics.FillPolygon(brushEnd, new Point[] { bottomLeft, topRight, bottomRight, bottomLeft });

            if (StartColor.ToArgb() != EndColor.ToArgb())
            {
                Pen black = new Pen(Color.Black, 1);
                e.Graphics.DrawLine(black, bottomLeft, topRight);
            }

        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // GradientPanel
            // 
            this.BackColor = System.Drawing.Color.Transparent;
            this.ResumeLayout(false);

        }
    }
}
